/**
 * MyDemoActivity.java
 * Copyright(C) 2014
 * creator:cuiran 2014-6-23 下午6:04:28
 */
package com.ghyf.mplay;



import org.videolan.vlc.audio.AudioServiceController;

import com.ghyf.mplay.bean.VideoSurfaceInfoTest;
import com.ghyf.mplay.datatype.POS;
import com.ghyf.mplay.util.LogUtil;

import android.app.Activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;

/**
 * 自定义播放器  测试
 * @author cuiran
 * @version 1.0.0
 */
public class MyDemoActivity extends Activity implements OnClickListener {
	private static final String TAG="MyDemoActivity";
	private ViewGroup viewGroup;
	private VideoSurfaceInfoTest surfaceInfo=null;
	private Button startBtn,stopBtn;
	
	public static MyDemoActivity instance=null;
	 @SuppressWarnings("deprecation")
	@Override
	 public void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);
		 //650,95,1250,800
		 WindowManager.LayoutParams layoutParams0 = getWindow().getAttributes(); 
		 layoutParams0.x=0-960+650;
		 layoutParams0.y=0-540+95;
		 layoutParams0.width=1250;
		 layoutParams0.height=800;
		 
		 instance=this;
		 viewGroup = new FrameLayout(getApplicationContext()); // 创建控件容器，显示布局
		 LayoutParams layoutParams1=new LayoutParams(1250, 800);
	
		 viewGroup.setLayoutParams(layoutParams1); // 设置容器的宽高
		 setContentView(viewGroup);
		 surfaceInfo=new VideoSurfaceInfoTest();
		 POS pos=new POS();
		 pos.setTop(95);
		 pos.setLeft(650);
		 pos.setWidth(1250);
		 pos.setHeight(800);
		 surfaceInfo.setModule_Pos(pos);
		 viewGroup.addView(surfaceInfo.getView(this));
		 
		
		 
//		 String bk_file_path="/sata/media/bg.jpg";
//		 Bitmap bk_bitmap = BitmapFactory.decodeFile(bk_file_path);
//		 BitmapDrawable bk_drawable = new BitmapDrawable(bk_bitmap);
//		 viewGroup.setBackgroundDrawable(bk_drawable);// 设置模板背景图片
		
	
		 surfaceInfo.startPlay();
		 //650,95,1250,800
	
		 
		 
	 }
	
	
	@Override
	protected void onPause() {
		super.onPause();
		AudioServiceController.getInstance().unbindAudioService(this);
		LogUtil.i(TAG, "onPause");
		surfaceInfo.onPause();
	}


	@Override
	protected void onResume() {
		super.onResume();
		AudioServiceController.getInstance().bindAudioService(this);
		LogUtil.i(TAG, "onResume");
		
	}
	
	@Override
	protected void onStop() {
		super.onStop();
		LogUtil.i(TAG, "onStop");
		surfaceInfo.onStop();
		
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		LogUtil.i(TAG, "onDestroy");
		surfaceInfo.onDestroy();
		
	 }

	class MyHandler extends Handler{

		/* (non-Javadoc)
		 * @see android.os.Handler#handleMessage(android.os.Message)
		 */
		@Override
		public void handleMessage(Message msg) {
			
			super.handleMessage(msg);
			switch (msg.what) {
			case 0:
				surfaceInfo.stopPlayback();
				
				
				break;

			default:
				surfaceInfo.startPlay();
				break;
			}
			
		}
		
	}
	Thread thread=null;
	Handler mHandler=new MyHandler();
	/* (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		Button b=(Button)v;
		if(b.equals(startBtn)){
//			mHandler.sendEmptyMessage(1);
			
			surfaceInfo.startPlay();
		}else {
			surfaceInfo.stopPlayback();
//			mHandler.sendEmptyMessage(0);
//			if(thread==null){
//				thread=new Thread(myRunnable);
//				
//			}
//			thread.start();
			
		}
		
	}
	
	Runnable myRunnable=new Runnable() {
		
		@Override
		public void run() {
			surfaceInfo.stopPlayback();
		}
	};
	
}
